package com.threegroup.admin.controller;


import com.github.pagehelper.PageInfo;
import com.threegroup.admin.dto.Flavor;
import com.threegroup.admin.entity.DishFlavorEntity;
import com.threegroup.admin.service.DishFlavorService;
import com.threegroup.common.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.awt.datatransfer.FlavorEvent;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("takeout/dishflavor")
public class DishFlavorConrtoller {
    @Resource
    private DishFlavorService dishFlavorService;

    @PostMapping
    public Result saveFlavor(@RequestBody DishFlavorEntity dishFlavorEntity){
        dishFlavorService.saveFlavor(dishFlavorEntity);

        return new  Result();
    }
    @PutMapping
    public Result updateFlavor(@RequestBody DishFlavorEntity dishFlavorEntity){
        dishFlavorService.updateFlavor(dishFlavorEntity);

        return new Result();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteFlavor(String ids){

        dishFlavorService.deleteFlavors(ids);
        return new  Result();

    }

    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("page")
    public Result<PageInfo<Flavor>> getFlavorList(Integer limit, Integer page, String order, String orderField){

        Result<PageInfo<Flavor>> result= dishFlavorService.getFlavorList(limit,page,order,orderField);
        System.out.println("使用了@GetMapping(page)");

        return result;
    }

    @GetMapping("{id}")
    public Result<List<Flavor>> queryFlavor(@PathVariable String id){

        Result<List<Flavor>> flavorEventResult = dishFlavorService.queryFlavor(id);
        System.out.println("使用了@GetMapping({id})");
        return flavorEventResult;
    }



}
